package main.java.com.negromotad.view.tableModelView;

import javax.swing.table.AbstractTableModel;

import org.apache.commons.lang.ArrayUtils;

public class TableModelView extends AbstractTableModel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3131277043128405530L;
	private String[] cols = null;
	private Object[][] data = null;

	public TableModelView(String[] cols) {
		String[] aux = { "Fila" };
		String[] newCols = (String[]) ArrayUtils.addAll(aux, cols);
		this.cols = newCols;

	}

	public void setFirstColName(String colName) {
		this.cols[0] = colName;
	}

	public int getColumnCount() {
		return cols.length;
	}

	public int getRowCount() {
		return data.length;
	}

	public String getColumnName(int col) {
		return cols[col];
	}

	public Object getValueAt(int row, int col) {
		return data[row][col];
	}

	public Object[][] getData() {
		return this.data;
	}

	public void setData(Object[][] data) {
		this.data = data;
	}

	/*
	 * JTable uses this method to determine the default renderer/ editor for
	 * each cell. If we didn't implement this method, then the last column would
	 * contain text ("true"/"false"), rather than a check box.
	 */
	public Class getColumnClass(int c) {
		return getValueAt(0, c).getClass();
	}

	/*
	 * Don't need to implement this method unless your table's editable.
	 */
	public boolean isCellEditable(int row, int col) {
		// Note that the data/cell address is constant,
		// no matter where the cell appears onscreen.
		if (col < 1) {
			return false;
		} else {
			return true;
		}
	}

	/*
	 * Don't need to implement this method unless your table's data can change.
	 */
	public void setValueAt(Object value, int row, int col) {
		data[row][col] = value;
		fireTableCellUpdated(row, col);
	}

}